import { http } from '@/utils/http'

export interface RegisterParams {
  userMobile: string
  userPwd: string
  companyId: number
  releationDeptIds: string // 关联部门ID 多个数据时用','分隔,如'35,36'
  postId: number
  realName: string
  email: string
  sex: number // 1:男 2:女
  agreedToTerms: boolean // 默认 true
}

/** 用户注册 */
export const register = (data: RegisterParams): Promise<IResData<any>> => {
  return http.post<any>('/api/Account/Register', { ...data })
}

export interface RegionItem {
  code: number
  name: string
  parent_code: number
  level: number
}

/** 获取地区列表 */
export const getRegion = (parentCode?: number): Promise<IResData<RegionItem[]>> => {
  return http.get<RegionItem[]>('/api/Account/GetRegion', { parentCode })
}

export interface SupplierCompanyItem {
  businessManager: string
  businessManagerEmail: string
  businessManagerMobile: string
  city: string
  cityCode: number
  companyManager: string
  companyManagerEmail: string
  companyManagerId: number
  companyManagerMobile: string
  createTime: string
  createUserId: number
  deptIds: string
  gfChannelManager: string | null
  gfSaleManager: string | null
  id: number
  isBasic: boolean | null
  parentId: number
  province: string
  provinceCode: number
  status: number
  supplierCompanyAddress: string
  supplierCompanyName: string
  updateTime: string
  updateUserId: number
}

export interface SupplierCompanyParams {
  provinceCode: number
  cityCode: number
  // companyName?: string
}

/** 获取供应商公司列表 */
export const getSupplierCompanyList = (
  params: SupplierCompanyParams,
): Promise<IResData<SupplierCompanyItem[]>> => {
  return http.get<SupplierCompanyItem[]>('/api/Account/GetSupplierCompanyList', params)
}

export interface DeptItem {
  deptId: number
  deptName: string
  englishDeptName: string
  deptCode: string
  parentId: number
  createTime: string
  createUser: number
  status: number
  deptDesc: string
  levelPath: string
  isStore: number
  deptType: string | null
  openTime: string | null
  closeTime: string | null
}

/** 获取部门列表 */
export const getDeptList = (companyId: number): Promise<IResData<DeptItem[]>> => {
  return http.get<DeptItem[]>('/api/Account/GetDeptList', { companyId })
}

export interface PostItem {
  createTime: string
  createUser: number
  defaultPromotionId: number
  deptId: number
  description: string
  parentId: number
  postCode: string
  postId: number
  postName: string
  roleId: number
  status: number
}

/** 获取所有岗位 */
export const getPostList = (): Promise<IResData<PostItem[]>> => {
  return http.get<PostItem[]>('/api/Account/GetPostList')
}

/**
 * 获取手机验证码
 * @param mobile 手机号码
 * @param type 验证码类型：1-注册，2-忘记密码
 */
export const getMobileCode = (mobile: string, type: 1 | 2): Promise<IResData<any>> => {
  return http.get<any>('/api/Account/GetMobileCode', { mobile, type })
}
/** 重置密码请求参数 */
export interface ResetPwdParams {
  forgetMobile: string // 手机号码
  forgetCode: string // 验证码
  newPwd: string // 新密码
}

/**
 * 忘记密码 - 重置密码
 * @param data 重置密码所需参数
 */
export const resetPassword = (data: ResetPwdParams): Promise<IResData<any>> => {
  return http.post<any>('/api/Account/ResetPwd', data)
}
